package com.ahsh1688.zhengshi.system.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ahsh1688.zhengshi.system.entity.TblUserinfo;
import com.ahsh1688.zhengshi.system.service.TblUserinfoService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.GetMapping;
import com.ahsh1688.zhengshi.util.PageResult;
import java.util.List;

/**
 *  
 *
 * @author 龙哥
 * @since 2023-12-19 15:11:57
 */
@RestController
@RequestMapping("/api/tblUserinfo")
@Api(tags = " 控制器")
public class TblUserinfoController {

    @Autowired
    private TblUserinfoService tblUserinfoService;

    /**
     * 分页查询
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "分页查询",notes = "分页查询",produces = "application/json")
    @ApiResponses({@ApiResponse(code = 200, message = "查询成功")})
    @PostMapping("/findPage")
    public ResponseEntity<PageResult<TblUserinfo>> findPage(@RequestBody TblUserinfo params) {
        PageResult<TblUserinfo> result = tblUserinfoService.findPage(params);
        return ResponseEntity.ok(result);
    }
    /**
     * 列表查询
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "列表查询",notes = "列表查询",produces = "application/json")
    @ApiResponses({@ApiResponse(code = 200, message = "查询成功")})
    @PostMapping("/findList")
    public ResponseEntity<List<TblUserinfo>> findList(@RequestBody TblUserinfo params) {
        List<TblUserinfo> result = tblUserinfoService.findList(params);
        return ResponseEntity.ok(result);
    }

    /**
     * 查询
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "查询", notes = "查询详情")
    @ApiResponses({@ApiResponse(code = 200, message = "查询成功")})
    @GetMapping("/{id}")
    public ResponseEntity<TblUserinfo> findById(@PathVariable("id") Long id) {
        TblUserinfo tblUserinfo = tblUserinfoService.findById(id);
        return ResponseEntity.ok(tblUserinfo);
    }

    /**
     * 新增
     *
     * @param tblUserinfo
     * @return
     */
    @ApiOperation(value = "新增", notes = "新增数据")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @PostMapping
    public ResponseEntity<Integer> insert( @Validated  @RequestBody TblUserinfo tblUserinfo) {
        int result = tblUserinfoService.insert(tblUserinfo);
        return ResponseEntity.ok(result);
    }

    /**
     * 修改
     *
     * @param tblUserinfo
     * @return
     */
    @ApiOperation(value = "修改", notes = "修改数据")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @PutMapping
    public ResponseEntity<Integer> update( @Validated  @RequestBody TblUserinfo tblUserinfo) {
        int result = tblUserinfoService.update(tblUserinfo);
        return ResponseEntity.ok(result);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "删除", notes = "删除数据")
    @DeleteMapping("/{id}")
    public ResponseEntity<Integer> delete(@PathVariable("id") Long id) {
        int result = tblUserinfoService.delete(id);
        return ResponseEntity.ok(result);
    }

}